﻿#include "ui_serialSet.h"
#include "ui_ui_serialSet.h"

Ui_SerialSet::Ui_SerialSet(QStringList portList, int portIdx, int baudIdx, QWidget *parent) :
    QDialog(parent),
    ui(new Ui::Ui_SerialSet)
{
    ui->setupUi(this);

    for (int i = 0; i < portList.size(); i++)
    {
        ui->port->addItem(portList.at(i));
    }

    ui->port->setCurrentIndex(portIdx);
    ui->baudRate->setCurrentIndex(baudIdx);

    connect(ui->cancel, &QPushButton::clicked, this, [=](){
        this->close();
        this->deleteLater();
    });

    connect(ui->ok, &QPushButton::clicked, this, [=](){
        ModbusRtuParam_t info;
        info.port        = ui->port->currentText();
        info.baud        = ui->baudRate->currentText().toUInt();
        info.dataBit     = ui->dataBit->currentIndex();
        info.stopBit     = ui->stopBit->currentIndex();
        info.Parity      = ui->parity->currentIndex();
        emit setSerialInfo(info);
        this->close();
        this->deleteLater();
    });
}

Ui_SerialSet::~Ui_SerialSet()
{
    delete ui;
}
